package com.example.config;

import java.io.*;

public class os2 {
    // 文本文件适合字符流
//    public static void main(String[] args) {
//
//        try (
//
//                Reader fileReader = new FileReader("D:\\company_project\\demo1\\src\\x.txt");
//                BufferedReader reader = new BufferedReader(fileReader);
//                Writer fileWriter = new FileWriter("D:\\company_project\\demo1\\src\\y.txt");
//                BufferedWriter writer = new BufferedWriter(fileWriter);
//        ) {
//            String line;
//            while ((line = reader.readLine()) != null) {
//                writer.write(line);
//                writer.newLine();
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//}


    public static void main(String[] args) {
              //用GBK的方式去读
        try(InputStream fileInputStream = new FileInputStream("D:\\company_project\\demo1\\src\\x.txt");
            Reader fileReader =  new InputStreamReader(fileInputStream,"GBK");
            BufferedReader reader = new BufferedReader(fileReader);
          //有utf-8
        OutputStream outputStream=    new FileOutputStream("D:\\company_project\\demo1\\src\\y.txt");
         Writer writers = new OutputStreamWriter(outputStream,"utf-8");
             BufferedWriter writer = new BufferedWriter(writers);
        ) {
           String line;
           while ((line = reader.readLine()) != null) {
            writer.write(line);
                writer.newLine();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
